layui.define(['element', 'api','utils','amis', 'econsole', 'editor', 'publish'], function(exports) {
    "use strict";

    /**
     * Button component
     * */
    var MOD_NAME = 'content',
        $ = layui.jquery,
        utils = layui.utils,
        econsole = layui.econsole,
        publish = layui.publish,
        editor = layui.editor,
        api = layui.api,
        amis = layui.amis
    ;

    var content = function(opt) {
        this.option = opt;
    };

    function addDom(option){
        var dom = `
              <div class="body-content">
                    <div class="body-left">
                        <div class="layui-side" id="editor"></div>
                        <div class="sidebar-draggable-icon"></div>
                    </div>
                    <div class="layui-body gs-body" id="editor_content_box">
                        <div class="gs-body-box">
                            <div id="fast-body">
                                <ul id="ztree" class="ztree"></ul>
                            </div>
        
                            <div id="content">
        
                            </div>
                        </div>
        
                    </div>
               </div>
            
        `
        $(option.elem).append(dom);
    }


    /**
     * Button start loading
     * */
    content.prototype.render = function(opt) {

        var option = {
            elem: opt.elem,
            enableConsole: opt.enableConsole,
            consoleSettings: opt.consoleSettings,
            editorSettings: opt.editorSettings
        }

        addDom(option);
        if(option.enableConsole){
            renderConsole();
        }

        if(option.editorSettings){
            option.editorSettings.elem = '#editor';
            editor.render(option.editorSettings);
        }


        return new content(option);
    }


    function renderConsole(){
        $('#editor_content_box').append(
            `
            <div id="console-box" class="console-box">
                <div class="console-drag"></div>
            </div>
            `
        )
        econsole.render({
            elem: '#console-box',
            collapsed: true
        })
    }

    exports(MOD_NAME, new content());
});
